package com.hnas.trade.mapper;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.hnas.core.mapper.Mapper;
import com.hnas.trade.dto.DTOOrder;
import com.hnas.trade.dto.DTOTradeRecord;
import com.hnas.trade.dto.GetOrderInfoByQRCodeReturn;
import com.hnas.trade.orm.Order;

public class OrderMapper extends Mapper<DTOOrder, Order>{
	private static OrderMapper mapper;
	private OrderMapper(){
		super(DTOOrder.class,Order.class);
	}
	public static OrderMapper getInstance(){
		if(mapper == null){
			mapper = new OrderMapper();
		}
		return mapper;
	}
	public DTOOrder mapToValue(Order vo){
		if(vo == null) return null;
		DTOOrder dto = new DTOOrder();
		BeanUtils.copyProperties(vo, dto);
		return dto;
	}
	public List<DTOOrder> mapToValue(List<Order> list){
		if(list == null) return null;
		List<DTOOrder> dtoList = new ArrayList<DTOOrder>();
		for(Order vo : list){
			dtoList.add(mapToValue(vo));
		}
		return dtoList;
	}
	
	public DTOTradeRecord mapToDTOTradeRecord(Order vo){
		if(vo == null) return null;
		DTOTradeRecord dto = new DTOTradeRecord();
		BeanUtils.copyProperties(vo, dto);
		return dto;
	}
	
	public GetOrderInfoByQRCodeReturn valueToGetOrderInfoReturn(Order order){
		GetOrderInfoByQRCodeReturn tReturn = new GetOrderInfoByQRCodeReturn();
		tReturn.setCard_no(order.getCardNo());
		tReturn.setMrch_id(order.getMrchId());
		tReturn.setMrch_name(order.getMrchName());
		tReturn.setMrch_type(order.getMrchType());
		tReturn.setNeed_pay(order.getNeedPay());
		tReturn.setOrder_detail(order.getOrderDetail());
		tReturn.setOrder_no(order.getOrderNo());
		tReturn.setOrder_status(order.getOrderStatus());
		tReturn.setPayment(order.getPayment());
		tReturn.setPsam_id(order.getPsamId());
		tReturn.setQrcode_no(order.getQrcodeNo());
		tReturn.setReal_pay(order.getRealPay());
		tReturn.setSub_code(order.getSubId());
		tReturn.setTrade_sno(order.getTradeSno());
		return tReturn;
	}
}
